//
//  HotViewViewController.m
//  GoTraveling
//
//  Created by 陈金山 on 15/12/23.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "HotViewViewController.h"
#import "CJSHotView.h"
#import "Resources.h"
#import "TypeTen.h"
#import "GSYTabbarViewController.h"

@interface HotViewViewController ()<CJSHotViewDelegate>

@property (nonatomic, retain) CJSHotView *hotView;

@property (nonatomic, retain) NSMutableArray *hotTenArray;

@end

@implementation HotViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.hotView = [[CJSHotView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49)];
    self.hotView.backgroundColor = self.view.backgroundColor;
    self.hotView.delegate = self;
    [self.view addSubview:self.hotView];

    
    self.hotTenArray = [NSMutableArray array];
}
- (void)AFNWorkingWithStart:(NSInteger)start {
    
    NSString *strUrl = [NSString stringWithFormat:@"http://api.breadtrip.com/v2/new_trip/spot/hot/list/?start=%ld", start];
    
    [Resources getDataWithName:strUrl block:^(id result) {
        
        NSDictionary *bigDic = result;
        NSArray *bigArray = [[bigDic objectForKey:@"data"] objectForKey:@"hot_spot_list"];
        for (NSDictionary *dic in bigArray) {
            
            TypeTen *typeTen = [[TypeTen alloc] init];
            [typeTen setValuesForKeysWithDictionary:dic];
            [self.hotTenArray addObject:typeTen];
        }
        self.hotView.tenArray = self.hotTenArray;
        if (start == 0) {
            [self.hotView endHeaderRefresh];
        }
        else {
            [self.hotView endFooterRefresh];
        }
        
    } error:^{
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"网络连接错误" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }];
        [alert addAction:action];
        
        [self presentViewController:alert animated:YES completion:nil];
    }];
}


- (void)getDataWithStart:(NSInteger)start {
    
    [self AFNWorkingWithStart:start * 12];
}

#pragma mark - push详情页面
- (void)pushDetailViewController:detailViewController {
    
    GSYTabbarViewController *baseTabbarC = (GSYTabbarViewController *)self.tabBarController;
    
    [baseTabbarC isHiddenTabBar:YES withViewController:detailViewController];
    [self.navigationController pushViewController:detailViewController animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
